//
//  LBViewController.m
//  LBPageMenu
//
//  Created by liuboliu on 09/21/2021.
//  Copyright (c) 2021 liuboliu. All rights reserved.
//

#import "LBViewController.h"
#import <LBPageMenu/LBPageMenu.h>

@interface LBViewController () <LBPageMenuDelegate, UIScrollViewDelegate>

@property (nonatomic, strong) LBPageMenu *menu;

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) NSArray *titleArray;

@end

@implementation LBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.titleArray = @[@"标题", @"中秋节", @"祝你快乐",@"啦啦啦",@"标题", @"中秋节", @"祝你快乐",@"啦啦啦",@"标题", @"中秋节", @"祝你快乐",@"啦啦啦",@"标题", @"中秋节", @"祝你快乐",@"啦啦啦"];
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.menu];

    [self.menu setItems:self.titleArray selectedItemIndex:0];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.menu beginMoveTrackerFollowScrollView:scrollView];
}

#pragma mark - LBPageMenuDelegate
- (void)selectItemAtIndex:(NSInteger)index
{
    [self.scrollView setContentOffset:CGPointMake(CGRectGetWidth(self.view.bounds) * index, 0) animated:YES];
}

#pragma mark - lazy load

- (LBPageMenu *)menu
{
    if (!_menu) {
        LBPageMenuConfiguration *configuration = [[LBPageMenuConfiguration alloc] init];
        configuration.unSelectedTitleColor = [UIColor cyanColor];
        configuration.selectedTittleColor = [UIColor magentaColor];
        ///指示条滚动风格，这里配置拉伸风格（默认是普通滚动）
        configuration.indicatorStyle = LBPageMenuIndicatorStyleLineChange;
        _menu = [[LBPageMenu alloc] initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.bounds), 50) configuration:configuration];
        _menu.delegate = self;
        _menu.backgroundColor = [UIColor lightGrayColor];
    }
    return _menu;
}

- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 300)];
        _scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds) * self.titleArray.count, 0);
        _scrollView.delegate = self;
        _scrollView.pagingEnabled = YES;
    }
    return _scrollView;
}

@end
